package org.example.mapper;

import org.apache.ibatis.annotations.*;
import org.example.pojo.Emp;
import org.example.pojo.EmpQueryParam;

import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {
    /*原始方式分页查询
    //查询总记录数
    @Select("select count(*) from emp e left join dept d on e.dept_id=d.id")
    public Long count();
    //分页查询
    @Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id=d.id " +
            "order by e.update_time desc limit #{start},#{pageSize} ")
    public List<Emp> list(Integer start,Integer pageSize);*/
    // PageHelper 实现分页查询
    //注意:
    //- PageHelper实现分页查询时，SQL语句的结尾一定一定一定不要加分号(;).。
    //- PageHelper只会对紧跟在其后的第一条SQL语句进行分页处理。(即对第一个使用empmapper.list()语句进行分页操作)
    /*@Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id = d.id\n" +
            "                           where e.name like '%%' and e.gender = 1 and e.entry_date between '2010-01-01' and '2021-12-31'\n" +
            "                           order by update_time desc ")*/
//    使用xml映射文件配置sql语句(#{}不能在''中使用,可以使用concat拼接字符串concat('%',#{},'%')(可以使用${}(不推荐)))
    public List<Emp> list(EmpQueryParam empQueryParam);

    //保存员工基本信息
    @Options(useGeneratedKeys = true, keyProperty = "id")//获取生成的主键--主键返回
    @Insert("insert into emp(username, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) " +
            "values(#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    /**
     * 根据id批量删除员工信息
     */
    void deleteByIds(List<Integer> ids);

    Emp getById(Integer id);

    /**
     * 根据id查询员工信息
     */
/*    @Select("select * from emp where id=#{id}")
    Emp getById(Integer id);
*/
//根据id修改员工信息
    void updateById(Emp emp);
    @MapKey("pos")
    List<Map<String,Object>> countEmpJobData();
    @MapKey("name")
    List<Map<String, Object>> countEmpGenderData();
    @Select("select * from emp where job=1")
    List<Emp> bzrlist();
    @Select("select * from emp where username=#{username} and password=#{password}")
    Emp findByUsernameAndPassword(Emp emp);
}